home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / ourcolor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-11  |  6.6 KB  |  238 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** THIS FILE IS FOR X11 IMPLEMENTATION ONLY
  5. **/
  6.  
  7. void 
  8. SRGP__initColor (requested_planes)
  9. {
  10.    srgp__available_depth = DefaultDepth(srgpx__display, srgpx__screen);
  11.  
  12.    srgp__base_colorindex = 0;
  13.  
  14.    if (srgp__available_depth == 1) {
  15.  
  16.       /***** PERFORMED FOR BILEVEL DISPLAYS */
  17.  
  18.       SRGP_BLACK = BlackPixel(srgpx__display,srgpx__screen);
  19.       SRGP_WHITE = WhitePixel(srgpx__display,srgpx__screen);
  20.       srgp__application_depth = 
  21.      srgp__max_pixel_value = 1;
  22.       srgp__base_colorindex = 0;
  23.    }
  24.    
  25.  
  26.    else {
  27.  
  28.       /****** PERFORMED FOR COLOR DISPLAYS */
  29.  
  30.       SRGP_BLACK = 1;
  31.       SRGP_WHITE = 0;
  32.  
  33.       if (requested_planes < 0) {
  34.      fprintf (stderr, "Fatal Error: insane parameter to SRGP_begin()\n\
  35.             Application requesting negative number of planes.\n");
  36.      exit(1);
  37.       }
  38.       if ((requested_planes == 0) || 
  39.       (requested_planes > srgp__available_depth)) 
  40.      srgp__application_depth = srgp__available_depth;
  41.       else
  42.      srgp__application_depth = requested_planes;
  43.       srgp__max_pixel_value = (1 << srgp__application_depth) - 1;
  44.  
  45.       if (srgp__application_depth == srgp__available_depth) {
  46.  
  47.      /***** APPL WANTS ENTIRE COLOR TABLE! */
  48.      srgpx__colormap = 
  49.         XCreateColormap (srgpx__display, 
  50.                  srgp__curActiveCanvasSpec.drawable.win,
  51.                  DefaultVisual(srgpx__display,srgpx__screen),
  52.                  AllocAll);
  53.      XSetWindowColormap (srgpx__display, 
  54.                  srgp__curActiveCanvasSpec.drawable.win,
  55.                  srgpx__colormap);
  56.       }
  57.       else {
  58.  
  59.      /***** APPL WANTS TO SHARE COLOR TABLE WITH THE OTHER CLIENTS */
  60.      unsigned long return_masks_here[8];
  61.      unsigned long return_pixels_here[1];
  62.      Status result;
  63.  
  64.      srgpx__colormap = DefaultColormap(srgpx__display,srgpx__screen);
  65.  
  66.      result = 
  67.         XAllocColorCells (srgpx__display,
  68.                   srgpx__colormap,
  69.                   TRUE /* contiguous planes desired */,
  70.                   return_masks_here,
  71.                   srgp__application_depth,
  72.                   return_pixels_here,
  73.                   1);
  74.  
  75.      if (result == 0) {
  76.          fprintf (stderr, "%s%s%s",
  77.               "SRGP finds the color table too full to share.  Therefore,\n",
  78.               "this application will have its own color table.  This will\n",
  79.               "cause screen colors to change when the mouse enters or leaves the window.\n");
  80.          /***** APPL WILL HAVE TO SHARE TABLE, EVEN THO IT DIDN'T WANT TO */
  81.          srgpx__colormap = 
  82.          XCreateColormap (srgpx__display, 
  83.                   srgp__curActiveCanvasSpec.drawable.win,
  84.                   DefaultVisual(srgpx__display,srgpx__screen),
  85.                   AllocAll);
  86.          XSetWindowColormap (srgpx__display, 
  87.                  srgp__curActiveCanvasSpec.drawable.win,
  88.                  srgpx__colormap);
  89.      } else
  90.          srgp__base_colorindex = return_pixels_here[0];
  91.      }
  92.  
  93.       /* Only first two entries of LUT are init'd */
  94.       XStoreNamedColor 
  95.      (srgpx__display, srgpx__colormap, "white", COLORINDEX(0), -1);
  96.       XStoreNamedColor 
  97.      (srgpx__display, srgpx__colormap, "black", COLORINDEX(1), -1);
  98.    }
  99.  
  100.  
  101.    /*** DONE FOR ALL CONFIGURATIONS. */
  102.    XSetWindowBackground (srgpx__display, 
  103.              srgp__curActiveCanvasSpec.drawable.win, 0);
  104.    XSetWindowBorder (srgpx__display, 
  105.              srgp__curActiveCanvasSpec.drawable.win, 1);
  106. }
  107.  
  108.  
  109.  
  110. void SRGP_loadColorTable
  111.    (int startentry, int count,
  112.     unsigned short *redi, 
  113.     unsigned short *greeni,
  114.     unsigned short *bluei)
  115. {
  116.    static XColor *x_color_structs = NULL;
  117.    static int cursize_of_x_cs_array = 0;  /* number of XColor structs */
  118.    register int i,j;
  119.    int endi;
  120.    register XColor *xcurcs;
  121.  
  122.  
  123.    /* LEAVE IMMEDIATELY IF EXECUTING ON BILEVEL DISPLAY */
  124.    if (srgp__available_depth == 1)
  125.       return;
  126.  
  127.    endi = startentry + count;
  128.  
  129.    DEBUG_AIDS{
  130.       SRGP_trace (SRGP_logStream, "SRGP_loadColorTable  %d  %d  %x %x %x\n",
  131.           startentry, count, redi, greeni, bluei);
  132.  
  133.       /* PERFORM CHECKING LEGALITY OF THE RANGE OF INDICES. */
  134.       srgp_check_pixel_value (startentry, "start");
  135.       srgp_check_pixel_value (endi-1, "end");
  136.    }
  137.  
  138.  
  139.    /* DYNAMICALLY (RE)ALLOCATE ARRAY OF XColor STRUCTURES */
  140.    if (cursize_of_x_cs_array < count) {
  141.       if (x_color_structs)
  142.      free ((char*)x_color_structs);
  143.       x_color_structs = (XColor*) malloc (sizeof(XColor)*count);
  144.       cursize_of_x_cs_array = count;
  145.  
  146.       /* Initialize a constant field of the XColor structs. */
  147.       for (i=0; i<count; i++)
  148.      x_color_structs[i].flags = -1;
  149.    }
  150.  
  151.    /* COPY INTENSITY VALUES INTO ARRAY. */
  152.    for (i=startentry, j=0, xcurcs=x_color_structs; i<endi; i++,j++,xcurcs++){
  153.       xcurcs->pixel = COLORINDEX(i);
  154.       xcurcs->red = redi[j];
  155.       xcurcs->green = greeni[j];
  156.       xcurcs->blue = bluei[j];
  157.    }
  158.  
  159.    XStoreColors (srgpx__display, srgpx__colormap, x_color_structs, count);
  160. }
  161.  
  162.  
  163.  
  164.  
  165. void
  166. SRGP_inquireColorTable 
  167.    (int startentry, int count,
  168.     unsigned short *redi, 
  169.     unsigned short *greeni,
  170.     unsigned short *bluei)
  171. {
  172.    static XColor *x_color_structs = NULL;
  173.    static int cursize_of_x_cs_array = 0;  /* number of XColor structs */
  174.    register int i,j;
  175.    int endi;
  176.    register XColor *xcurcs;
  177.  
  178.  
  179.    /* LEAVE IMMEDIATELY IF EXECUTING ON BILEVEL DISPLAY */
  180.    if (srgp__available_depth == 1)
  181.       return;
  182.  
  183.    endi = startentry + count;
  184.  
  185.    DEBUG_AIDS{
  186.       /* PERFORM CHECKING LEGALITY OF THE RANGE OF INDICES. */
  187.       srgp_check_pixel_value (startentry, "start");
  188.       srgp_check_pixel_value (endi-1, "end");
  189.    }
  190.  
  191.  
  192.    /* !!!!!! LATER, THIS SHOULD USE SAME ARRAY AS IN color_X11.c */
  193.  
  194.    /* DYNAMICALLY (RE)ALLOCATE ARRAY OF XColor STRUCTURES */
  195.    if (cursize_of_x_cs_array < count) {
  196.       if (x_color_structs)
  197.      free ((char*)x_color_structs);
  198.       x_color_structs = (XColor*) malloc (sizeof(XColor)*count);
  199.       cursize_of_x_cs_array = count;
  200.    }
  201.  
  202.    for (i=startentry, xcurcs=x_color_structs; i<endi; i++,xcurcs++) {
  203.       xcurcs->pixel = COLORINDEX(i);
  204.       xcurcs->flags = -1;
  205.    }
  206.  
  207.    XQueryColors (srgpx__display, srgpx__colormap, x_color_structs, count);
  208.  
  209.  
  210.    /* COPY INTENSITY VALUES INTO USER'S ARRAY. */
  211.    for (j=0, xcurcs=x_color_structs; j<count; j++,xcurcs++){
  212.       redi[j] = xcurcs->red;
  213.       greeni[j] = xcurcs->green;
  214.       bluei[j] = xcurcs->blue;
  215.    }
  216. }
  217.  
  218.  
  219.  
  220.  
  221. void
  222. SRGP_loadCommonColor (entry, name)
  223. int entry;
  224. char *name;   /* Null-terminated string of characters */
  225. {
  226.    /* IGNORE IF MONOCHROME */
  227.    if (srgp__available_depth == 1)
  228.       return;
  229.  
  230.    DEBUG_AIDS{
  231.       SRGP_trace (SRGP_logStream, "SRGP_loadCommonColor  %d  %s\n", entry, name);
  232.       srgp_check_pixel_value (entry, "start/end");
  233.    }
  234.  
  235.    XStoreNamedColor 
  236.       (srgpx__display, srgpx__colormap, name, COLORINDEX(entry), -1);
  237. }
  238.